/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include "post.h"
#include "thread.h"

namespace Wishmaster
{
	Post::Post(const PostId& postId) : m_id(postId), m_expanded(false),
		m_visibility(Normal)
	{
	}

	Post::~Post()
	{
	}

	void Post::setText(QString const& text)
	{
		m_text = text;
	}

	QString const& Post::text()
	{
		return m_text;
	}

	void Post::setTopic(QString const& topic)
	{
		m_topic = topic;
	}

	QString const& Post::topic()
	{
		return m_topic;
	}

	void Post::setName(const QString& name)
	{
		m_name = name;
	}

	QString Post::name()
	{
		return m_name;
	}

	void Post::setTimestamp(const QDateTime& dt)
	{
		m_timestamp = dt;
	}

	QDateTime Post::timestamp() const
	{
		return m_timestamp;
	}

	void Post::setExtra(const QString& key, ExtraInfo info)
	{
		m_extra.setExtra(key, info);
	}

	ExtraInfo Post::extra(const QString& key) const
	{
		return m_extra.extra(key);
	}

	QStringList Post::extraList()
	{
		return m_extra.extraList();
	}

	PostId Post::id()
	{
		return m_id;
	}

	void Post::addReply(const PostId& id)
	{
		if(!m_replies.contains(id))
			m_replies.append(id);
	}

	QList<PostId> Post::replies()
	{
		return m_replies;
	}

	void Post::clearReplies()
	{
		m_replies.clear();
	}

	void Post::setExpanded(bool e)
	{
		m_expanded = e;
	}

	bool Post::isExpanded()
	{
		return m_expanded;
	}

	ExtraContainer Post::extraContainer()
	{
		return m_extra;
	}

	int Post::attachmentCount()
	{
		return m_attachments.size();
	}

	AttachmentPtr Post::attachment(int index)
	{
		return m_attachments.at(index);
	}

	void Post::addAttachment(const AttachmentPtr& attach)
	{
		m_attachments.append(attach);
	}

	void Post::setVisibility(ComponentVisibility newVisibility)
	{
		m_visibility = newVisibility;
	}

	ComponentVisibility Post::visibility() const
	{
		return m_visibility;
	}

	bool Post::hasImages()
	{
		foreach(const AttachmentPtr& attach, m_attachments)
		{
			if(attach->type().startsWith("image"))
				return true;
		}
		return false;
	}
}

